In the Java inheritance mechanism, subclasses can overwrite methods in the parent class.
Base.java
public class Base {public
base () {
System.out.println ("base");
}
public void Foo () {
System.out.println (' foo in Father ');
}
Checket.java:
public class Checket extends Base {public
checket () {
super ();
System.out.println ("Checket");
}
Tag:ar use spjavaon data divbs code 1. Subclass constructors If you want to refer to super, you must put super in the first place of the function. class Base {base () {system.out.println ("base"); } }public class Checket extends Base {checket () {super ();//Call the constructor of the parent class, be sure to put it in the first statement of the method system.out.println ("
super cannot coexist, and the next one where this or super appears must be the 1th sentence of the construction method;Static methods, that is, cannot have this and Super keyword in a class method1. Subclass constructors If you want to refer to super, you must put super in the first place of the function. class Base {Base () {System.out.println ( "base" ); }} public class checket extends Base {Checket
1. Subclass constructors If you want to refer to super, you must put super in the first place of the function.class Base {Base () {System. out. println ("Base");}} Publicclass Checket extends Base {Checket () {Super ();//Call the constructor of the parent class, be sure to put it in the first statement of the methodSystem. out. println ("Checket");} PublicStatic
1. Constructor of subclass if you want to refer to super, you must put super at the top of the function
Copy Code code as follows:
Class Base {
Base () {
System.out.println ("Base");
}
}
public class Checket extends Base {
Checket () {
Super ();//Call the Parent class construction method, be sure to place the first statement of the method
System.out.println ("
Reprinted from: http://blog.csdn.net/anmei2010/article/details/4093118
1. Sub-class constructor if you want to reference super, you must put super in the first place of the function.
Class base {base () {system. out. println ("base") ;}} publicclass checketextends base {checket () {super (); // call the constructor of the parent class, which must be placed in the first statement system of the method. out. println ("
1. Subclass constructors If you want to refer to super, you must put super in the first place of the function. class Base {base () {System.out.println ("base"); }} public class Checket extends Base {checket () {super ();//Call the constructor of the parent class, be sure to place the first statement of the method System.out.println ("Che Cket "); } public static void Main (String argv[]) {
1. Subclass constructors If you want to refer to super, you must put super in the first place of the function . 1 classBase {2 Base () {3System.out.println ("Base");4 }5 }6 7 Public classChecketextendsBase {8 Checket () {9 Super();//call the constructor of the parent class, and be sure to put it in the first statement of the methodTenSystem.out.println ("Checket"); One } A - Public
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.